<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script type="text/javascript">
function inicializarFiltro($filtro,$inputKey,$limpar) {
	$($limpar).bind("click",function(event) {
		$inputKey.val("");
		$($filtro).submit();
	  });

	$inputKey.bind("click",function(event) {
		$(this).clearDefault();
	  });
	
	$inputKey.bind("blur",function(event) {
		$(this).loadDefault();
	  });	
	
	$($filtro).bind("submit",function(event) {
		$inputKey.clearDefault();
	  });
}
</script>
<script type="text/javascript">
	function xhrStatus(response, status, xhr) {
		if (status == "error") 
			alert("Erro no XHR: " + xhr.status + " " + xhr.statusText);
	};
	
	$(document).ready(function () {
		$("a.btn").button();
	
		var $ui = $("#ui-tabs-3");
		var urlAjax = "admmin/cadastramentos/professoresExternos";

		$(".bt-page").click(function(event) {
			 event.preventDefault();
			 url = $(this).attr("href");
			 $ui.load(url,{keyword:"${keyword}"},xhrStatus);
		});
		
		$("#bt-newers").click(function(event) {
			 event.preventDefault();
			 url = $(this).attr("href");		 
			 $ui.load(url,{keyword:"${keyword}"},xhrStatus);
		}).button({icons: {primary: 'ui-icon ui-icon-triangle-1-w'},text: false});
		
		$("#bt-olders").click(function(event) {
			 event.preventDefault();
			 url = $(this).attr("href");
			 $ui.load(url,{keyword:"${keyword}"},xhrStatus);
		}).button({icons: {primary: 'ui-icon ui-icon-triangle-1-e'},text: false});
		
		$filtro = $("#ui-tabs-1 #filtro");
		$inputKey = $("#ui-tabs-1 #f-keyword");
		$limpar = $("#ui-tabs-1 #f-limpar");
		
		inicializarFiltro($filtro,$inputKey,$limpar);
		$filtro.bind("submit",function(event,form) {
		 event.preventDefault();
		 $filtro.ajaxSubmit({
			url: urlAjax,
			type: 'post',
			success: function(data) {
		  		$ui.html(data);
			}					
		 });
	});		  		
});
</script>
<script type="text/javascript">
	$(function() {
		
		$("#dialog-detalhes-prof-externo").dialog({
			autoOpen: false,
			modal: true,
			beforeclose: function(event, ui) {
				$('#content_prof_externo',this).text("");
				externo_id = 0;
			}
		});
		
		$(".btn-detalhes-prof-externo").click(function (event) {
			var loader = $('#loader_prof_externo');
			var dialog = $('#dialog-detalhes-prof-externo');
			var content	= $('#dialog-detalhes-prof-externo #content_prof_externo');
			var title = "Detalhes do Profº Externo";

			loader.show();
			event.preventDefault();
			dialog.dialog("option" , "title" , title);
			dialog.dialog('open');
			content.load($(this).attr("href"), function() {
				$('#loader_prof_externo').hide();					
				externo_id = $("#externo_id").val();
			});
			loader.hide();
		});
	});
</script>
	<c:if test="${fn:containsIgnoreCase(usuarioLogado.rolesString, 'SECRETARIO')}">		
	<a href="admin/cadastramentos/inserirProfExterno" class="btn">Inserir Profº Externo</a>
	</c:if>		
	<br>				
	<c:forEach items="${externos}" var="externo">
		<div class="user_line">
			${externo.nome} [ ${externo.instituicaoDeOrigem} ]
			
			<div style="float: right;">
				<c:if test="${fn:containsIgnoreCase(usuarioLogado.rolesString, 'SECRETARIO')}">
					<a href="admin/cadastramentos/removerProfExterno-${externo.id}" class="btn" onclick="return confirm_delete()">remover</a>
					<a href="admin/cadastramentos/editarProfExterno-${externo.id}" class="btn">editar</a>								
					<a href="admin/professores-convidados/${externo.id}" class="btn btn-detalhes-prof-externo">detalhes</a>
				</c:if>
			</div>
		</div>
	</c:forEach>
	
<div id="dialog-detalhes-prof-externo" title="Detalhes do Profº Externo #">
	<center><img src="static/imagens/ajax-loader.gif" id="loader_prof_externo"/></center>
	<div id="content_prof_externo">
	</div>
</div>
	<%@include file="../includes/paginacao.jsp" %>